home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: cdf.toronto.edu!news
- From: Paul Dowman <a209dowm@cdf.utoronto.ca>
- Subject: Re: overloaded operator question
- Content-Type: text/plain; charset=us-ascii
- Message-ID: <DLG020.DzL@cdf.toronto.edu>
- Sender: news@cdf.toronto.edu (Usenet News)
- Nntp-Posting-Host: lysander
- Content-Transfer-Encoding: 7bit
- Organization: Computing Disciplines Facility, University of Toronto
- References: <4dmin1$160@noc2.drexel.edu> <4domv0$hfk@charnel.ecst.csuchico.edu>
- Mime-Version: 1.0
- Date: Fri, 19 Jan 1996 19:13:10 GMT
- X-Mailer: Mozilla 1.1N (X11; I; SunOS 5.3 sun4c)
- X-Url: news:4domv0$hfk@charnel.ecst.csuchico.edu
-
- >Just to clean things up a bit, seeing as how you are not altering
- >either the left or right operand here, but instead returning a
- >new (temporary) matrix as the result of the operation, your
- >method declaration should be:
- >
- > Matrix Matrix::operator * (const Matrix & right) const;
-
-
-
- why not declare the operator outside the object? eg:
-
- matrix operator * (matrix &matrix_a, matrix &matrix_b)
- {
- // returns a third temp matrix object
- }
-
- then when you use it:
- matrix_c = matrix_a * matrix_b;
-
- This is how I have done it, following examples in the O'Reilly book "Practical
- C++ Programming" (I am learning it now)
-
- - Paul.
-
-